﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using LDriver;

namespace LClient
{
    public partial class ucMeasurements : UserControl
    {
        public ucMeasurements()
        {
            InitializeComponent();
        }

        private void ucMeasurements_Load(object sender, EventArgs e)
        {

        }

        const float PI = 3.141592654F;

        float fCenterX;
        float fCenterY;

        private float fSecThickness;
        private float fSecLength;
        Color secColor = Color.Red;

        private Measurement m;

        public void AddMeasurements(Measurement measurement)
        {
            m = measurement;
            this.Refresh();
        }

        private void ucMeasurements_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            try
            {
                this.fSecThickness = (float)this.Height / 200;
                this.fSecLength = (float)this.Height / 3 / 1.15F;

                float fRadSec = m.Angle * 6 * PI / 180;

                DrawLine(this.fSecThickness, this.fSecLength, secColor, fRadSec, e);

            }
            catch (Exception)
            {
            }

        }

        private void DrawLine(float fThickness, float fLength, Color color, float fRadians, System.Windows.Forms.PaintEventArgs e)
        {
            e.Graphics.DrawLine(new Pen(color, fThickness),
                fCenterX - (float)(fLength / 9 * System.Math.Sin(fRadians)),
                fCenterY + (float)(fLength / 9 * System.Math.Cos(fRadians)),
                fCenterX + (float)(fLength * System.Math.Sin(fRadians)),
                fCenterY - (float)(fLength * System.Math.Cos(fRadians)));
        }

    }
}
